import React from 'react';
import { SuperTable, SuperTableProps } from '@/components/SuperTable';
import { User } from '@/types/sys-type';
import { factory } from '@/utils/column';
import { Button, DatePicker } from 'antd';

export default () => {
  const columns: SuperTableProps<User, any>['columns'] = [
    ... factory.getAbstractIdBaseEntityColumns() as any,
    { dataIndex: 'username', title: '账号', width: 200 },
    {
      dataIndex: 'password',
      title: '密码',
      hideInTable: true,
      hideInSearch: true,
      hideInForm: true,
      hideInDescriptions: true,
    },
    { dataIndex: 'name', title: '姓名', width: 200 },
    {
      dataIndex: 'gender', title: '性别', width: 100, valueType: 'radio', valueEnum: {
        '1': { text: '男' },
        '2': { text: '女' },
      },
    },
    {
      dataIndex: 'birthday',
      title: '生日',
      width: 200,
      valueType: 'date',
      renderFormItem: () => <DatePicker.RangePicker />,
    },
    { dataIndex: 'identityCard', title: '身份证号', width: 200, ellipsis: true },
    {
      dataIndex: 'phone', title: '电话号码', width: 100,
    },
    { dataIndex: 'mobile', title: '手机号码', width: 100 },
    { dataIndex: 'email', title: '邮箱地址', width: 100 },
    { dataIndex: 'accountExpiredTime', title: '账号过期时间', width: 100 },
    {
      dataIndex: 'accountNonLocked', title: '是否锁定', valueType: 'radio', width: 100, valueEnum: {
        true: { text: '是' },
        false: { text: '否' },
      },
    },
    { dataIndex: 'passwordErrorTimes', title: '密码错误次数', width: 100 },
    { dataIndex: 'passwordModifyTime', title: '密码修改时间', width: 100 },
    {
      dataIndex: 'enabled', title: '是否启用', width: 100, valueType: 'radio', valueEnum: {
        true: { text: '是' },
        false: { text: '否' },
      },
    },
  ];

  console.log(columns);

  const instance = SuperTable.useTableRef();

  return <SuperTable<User>
    instance={ instance }
    columns={ factory.wrapperProColumns(columns) }
    dataSource={ [ { id: 'x', email: '1028203709@qq.com', accountNonLocked: true }, {
      id: '2',
      email: '222@qq.com',
      accountNonLocked: true,
    } ] }
    toolBarRenderMerge={ () => {
      return {
        type: 'before',
        actions: [ <Button>privat11111111111e</Button> ],
        // global: { type: 'link', shape: 'circle' },
        create: {
          shape: 'default',
          children: '创建用户',
          type: 'primary',
          schema: {
            // columns: [],
            // layoutType: 'Form'
            submitter: false,
            onFinish: (values) => {
              console.log(values);
              return Promise.reject('成功');
            },
            title: '新增用户',
          },
        },
        import: {
          shape: 'round',
        },
      };
    } }
    // toolBarRender={false}
    toolbar={
      {
        // style: {
        //   display: 'none',
        // }
        // settings: []
        // actions: [ <a onClick={ () => {
        //   console.log(instance);
        //   console.log(instance.current.getFieldsValue());
        // } }>x</a> ],
        subTitle: 'xxx',
        title: 'oooo',
      }
    }
    expandable={
      {
        expandedRowRender: (record, index, indent, expanded) => {
          console.log(record, index, indent, expanded);
          return <a>xxx</a>;
        },
        columnTitle: '测试',
      }
    }
  />;
};
